/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package manager.auxiliares;

import java.util.LinkedList;
import javax.swing.DefaultListModel;
import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

/**
 *
 * @author Thiago
 */
public class AutoComplete {

    JList jList;
    JScrollPane jScrollPane;
    int x;
    int y;
    int width;
    int height;
    String searchWord;
    JTextField jTextField;

    public AutoComplete(final JList jList, final JScrollPane jScrollPane, JTextField jTextField) {
        this.jList = jList;
        this.jScrollPane = jScrollPane;
        this.x = jScrollPane.getX();
        this.y = jScrollPane.getY();
        this.width = jScrollPane.getWidth();
        this.height = jScrollPane.getHeight();
        this.jTextField = jTextField;
        searchWord = "";
    }

    public void update(LinkedList<String> linkedList) {
        DefaultListModel model = new DefaultListModel();
        for (int i = 0; i < linkedList.size(); i++) {
            model.addElement(linkedList.get(i));
        }

        jList.setModel(model);
        if (linkedList.size() > 0) {
            jScrollPane.setVisible(true);
            if (linkedList.size() < 3) {
                jList.setVisibleRowCount(linkedList.size());
                if (linkedList.size() == 1) {
                    jScrollPane.setBounds(x, y, width, 23);
                }
                if (linkedList.size() == 2) {
                    jScrollPane.setBounds(x, y, width, 40);
                }
            } else {
                jList.setVisibleRowCount(3);
                jScrollPane.setBounds(x, y, width, height);
            }
        } else {
            jScrollPane.setVisible(false);

        }
    }
    
    public JScrollPane getjScrollPane() {
        return jScrollPane;
    }

    public String getSearchWord() {
        return searchWord;
    }

    public JTextField getjTextField() {
        return jTextField;
    }

    public void setSearchWord(String searchWord) {
        this.jTextField.setText(searchWord);
        this.searchWord = searchWord;
    }

    public JList getjList() {
        return jList;
    }
}
